var jsonFile = require('jsonfile')
var fileName = 'et.json'
const axios = require('axios')
var jsonData = jsonFile.readFileSync(fileName)
const qs = require('qs')

const phone = jsonData.phone
const pwd = jsonData.pwd
const token = jsonData.token
const pay_pwd = jsonData.pay_pwd
const goods = jsonData.goods
var requestArray = []

const instance = axios.create({
  credentials: true,
  baseURL: 'https://nft.etqfnb.com',
  headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36' }
})
instance.defaults.headers['Content-Type'] = 'application/json;'
instance.defaults.headers['token'] = token





pushList()


// 商品列表填充
function pushList() {
  setInterval(() => {
    for (let item in goods) {
      instance.post('/api/collection_info/collection_stock', { collection_info_id: goods[item].id, order_price: 'asc' }).then(res => {
        let data = res.data.data.data[0]
        let price = data.price
        let id = data.id
        let name = data.collectioninfo.collection_name
        console.log('商品:' + name + '最低价为:' + price + '------价格低于:' + goods[item].price + '时将自动锁定')
        if (price <= goods[item].price) {
          instance.post('/api/collectionissue/create', { collection_stock_id: id }).then(res => {
            if (res.data.code == 1) {
              console.log(res.data)
              axios.post('https://open.feishu.cn/open-apis/bot/v2/hook/9234b14f-e535-41e2-98dd-309f1fd2b580', { "msg_type": "text", "content": { "text": "ET锁单成功,请上号支付!!!" + ",价格为:" + price } })
            } else {
              console.log(res.data.msg)
            }
          }).catch(err => {
            console.log('频繁')
          })
        }
      }).catch(err => {
        console.log(err)
      })
    }
  }, 200)
}